package com.qk.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qk.entity.Course;
import com.qk.management.mapper.CourseMapper;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *  @author SHCJ
 *  @created 2025/10/7 19:40
 *  @description
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public IPage<Course> selectByPage(String name, Integer target, Integer subject, Integer page, Integer pageSize) {
        LambdaQueryWrapper<Course> queryWrapper = new LambdaQueryWrapper<>();
        if (name != null && !name.isEmpty()) {
            queryWrapper.like(Course::getName, name);
        }
        if (target != null) {
            queryWrapper.eq(Course::getTarget, target);
        }
        if (subject != null) {
            queryWrapper.eq(Course::getSubject, subject);
        }
        queryWrapper.orderByDesc(Course::getUpdateTime);
        Page<Course> coursePage = new Page<>(page, pageSize);
        return courseMapper.selectPage(coursePage, queryWrapper);
    }
}
